package com.ddx.service.impl;

import com.ddx.check.CheckProvideIdeaParamValidate;
import com.ddx.dao.ProvideIdeaMapper;
import com.ddx.dto.ProvideIdeaDto;
import com.ddx.pojo.ProvideIdea;
import com.ddx.service.ProvideIdeaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: liyuxiang
 * @create: 2018-11-10
 */
@Service
public class ProvideIdeaServiceImpl implements ProvideIdeaService {

    @Autowired
    ProvideIdeaMapper provideIdeaMapper;

    @Override
    @Transactional
    public void insert(ProvideIdeaDto provideIdeaDto)  throws Exception{
        // 检查参数
        CheckProvideIdeaParamValidate.insert(provideIdeaDto);
        // 组装数据
        ProvideIdea provideIdea = new ProvideIdea();
        provideIdea.setUserId(provideIdeaDto.getUserId());
        provideIdea.setContent(provideIdeaDto.getContent());
        provideIdea.setImages(provideIdeaDto.getImages());
        provideIdea.setType(provideIdeaDto.getType());
        // 添加返回
        provideIdeaMapper.insertSelective(provideIdea);
    }

    @Override
    @Transactional
    public List<ProvideIdea> list(ProvideIdeaDto provideIdeaDto) throws Exception {
        // 检查参数
        CheckProvideIdeaParamValidate.list(provideIdeaDto);
        // 组装数据
        // 添加返回
        return provideIdeaMapper.getList4userId(provideIdeaDto.getUserId());
    }
}
